<template>
	<view style="padding: 10vmin;">
		<bottomNav></bottomNav>
		<view class="flex-center" style="height: calc(100vh - 20vmin);width: 100%;flex-direction: column;">

			<!-- 登录逻辑 -->
			<view v-if="token == ''" style="width: 100%;height: 100%;" class="flex-center">
				<view style="flex: 1;height: 100%;">
					<u-image src="/static/images/learn.png" mode="aspectFit" style="height: 100%;width: 100%;">
					</u-image>
				</view>
				<view style="flex: 2;height: 100%;flex-direction: column;" class="flex-center">
					<view style="flex: 3;width: 100%;" class="flex-center font-2"></view>
					<view style="flex: 1;width: 100%;" class="flex-center font-2">Login</view>
					<view style="flex: 9;width: 100%;">
						<view style="margin: 10vmin;">
							<view
								style="width: 100%;height: 6vmax;flex-direction: column;justify-content: start;align-items: center;gap"
								class="flex-center">
								<light-box label="Username" labelWidth="10vmax" labelLeftMargin="2vmin">
									<template #labelRight>
										<input v-model="username" placeholder="Input Username..."
											style="height: 100%;margin-left: 1vmax;" />
									</template>
								</light-box>
								<light-box style="margin-top: 2.5vmax;" label="Password" labelWidth="10vmax"
									labelLeftMargin="2vmin">
									<template #labelRight>
										<input v-model="password" placeholder="Input Password..."
											style="height: 100%;margin-left: 1vmax;" />
									</template>
								</light-box>
							</view>
							<u-button @click="OnClickLogin"
								style="margin-top: 10vmax; width: 32vw;height: 3vmax;font-size: 1vmax;">Login</u-button>
						</view>
					</view>
				</view>
			</view>
			<view v-if="token != ''" style="width: 100%;height: 100%;" class="flex-center">
				<u-button @click="$u.vuex('token','')">Logout</u-button>
			</view>
		
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: ''
				, password: ''
			}
		}
		, methods: {
			OnClickLogin() {
				console.log('login');
				this.$u.api.post_login({
					username: this.username
					, password: this.password
				}).then(res => {
						this.$refs.uToast.show(this.$u.util.parseToastArgs(res))
						if (res.code == 200) {
							this.$u.vuex("token", res.token)
						}
					}
				)
			}
		}
		, onLoad() {
			this.$u.vuex('pageIndex', 2)
		}
	}
</script>

<style>

</style>
